﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using WebRSSBuilder.Web;

namespace WebRSSBuilder.Helpers
{
    public class RoleTypeConverter : IValueConverter
    {
        public DomainDataSource ItemsSource { get; set; }


        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            aspnet_Roles returnvalue = null;
            if (value != null)
            {
                Guid RoleID = (Guid)value;
               
                foreach (var item in ItemsSource.Data)
                {
                    aspnet_Roles r = (aspnet_Roles)item;
                    if (r.RoleId == RoleID)
                    {
                        returnvalue = r;
                        break;
                    }
                }
            }
            else
            {
                returnvalue = null; 
            }
            return returnvalue;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                aspnet_Roles r = (aspnet_Roles)value;
                Guid id = Guid.Empty;
                if (r != null)
                    id = r.RoleId;
                return id; 
            }
            else
                return null; 
            
        }
    }
}